using System;
using System.Collections.Generic;
using System.Text;

namespace Sedna.Core.Persistence.Hql
{
    public class HqlFromToken
    {
        private HqlFromClause fromClause;
        private StringBuilder token = new StringBuilder();

        public HqlFromToken(HqlFromClause fromClause, string entity)
        {
            this.fromClause = fromClause;
            token.Append(entity);
        }

        public HqlFromToken InnerJoin(string property)
        {
            token.Append(" inner join ").Append(property);
            return this;
        }

        public HqlFromToken InnerJoin(string property, bool fetch)
        {
            token.Append(String.Format(" inner join {0} ", fetch? "fetch" : "")).Append(property);
            return this;
        }

        public HqlFromToken LeftJoin(string property)
        {
            token.Append(" left outer join ").Append(property);
            return this;
        }

        public HqlFromToken LeftJoin(string property, bool fetch)
        {
            token.Append(String.Format(" left outer join {0} ", fetch ? "fetch" : "")).Append(property);
            return this;
        }

        public HqlFromToken RightJoin(string property)
        {
            token.Append(" right outer join ").Append(property);
            return this;
        }
        
        public HqlFromToken FullJoin(string property)
        {
            token.Append(" full join ").Append(property);
            return this;
        }
        
        public HqlFromToken Add(string entity)
        {
            return fromClause.Add(entity);
        }

        public override string ToString()
        {
            return token.ToString();
        }
    }
}
